package edu.colorado.epmapp.network;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;

import edu.colorado.epmapp.models.User;


public class HomeNetwork extends BaseNetwork {
	
	public HomeNetwork(String newBase){
		super(newBase);
	}

	/**
	 * Because of the way the server is currently set up, this method will merely perform
	 * an HttpGet request using the username/password provided by the user in the header
	 * auth credentials. Then if the username and password are correct, the response status
	 * code will contain 200, otherwise it should contain a 401 unauthorized status.
	 * 
	 * @param listener - the callback listener
	 */
	public void login(OnResponseListener listener){
		client.getCredentialsProvider().setCredentials(
				new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), 
				new UsernamePasswordCredentials(User.getUser().getUsername(), User.getUser().getPassword()));
		HttpGet getRequest = new HttpGet(baseURL+"petreport");
		HttpResponse response;
		String finalResponse = null;
		try {
			response = client.execute(getRequest);
			finalResponse = response.getStatusLine().toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("error: "+e.toString());
		}
		listener.onRequestComplete(finalResponse);
	}
	
	//This endpoint has not been added to the server API yet.
	/*public void register(String request){
		submitRequest("accounts/register", request);
	}*/
	
}
